<template>
<div style="height:100%">
  <xdh-layout class="case layout" :fixed="true" :west="westOpt" :north="northOpt"> 
    <div class="xdh-admin__sidebar" slot="west">
      <div class="xdh-admin__switch" @click="toggleSidebar">
        <i class="iconfont icon-collapsed" :class="{'is-collapsed': menuCollapsed}"></i>
      </div>
      <xdh-menu-toggle class="xdh-admin__menu collapsible" 
        popper-class="xdh-admin__popper" :data="menus" 
        :collapse="menuCollapsed" :router="true"
        @select="menuSelectHandle"
      ></xdh-menu-toggle>
    </div>

    <div class="case-main">
      <div class="nav-wrap">
        <xdh-nav-tabs :store="tabStore"></xdh-nav-tabs>
      </div>
      <div class="view-wrap">
        <router-view></router-view>
      </div>
    </div>
  </xdh-layout>
</div>
</template>

<style lang="scss" scoped>
@import '../../../extension/xdh-admin/style.scss';
.case.layout{
  /deep/ .xdh-admin__sidebar {
    background: $--color-primary-light-7;
  }
  /deep/ .xdh-admin__switch{
    height: 30px;
    line-height: 30px;
    font-size: 20px;
    padding: 0;
  }
  .case-main{
    display: flex;
    flex-flow: column;
    height: 100%;
    .nav-wrap{
      flex: 0 0 auto;
    }
    .view-wrap{
      flex: 1;
      overflow: hidden;
    }
  }
}
</style>

<script>
import XdhLayout from '@/widgets/xdh-layout'
import XdhMenuToggle from '@/widgets/xdh-menu-toggle'
import XdhNavTabs from '@/widgets/xdh-nav-tabs'
import createStoreModule from '@/widgets/xdh-nav-tabs/store'
const STORE_NAME = 'nav-tabs'
const iconList = ['el-icon-goods', 'el-icon-setting', 'el-icon-phone', 'el-icon-news', 'el-icon-tickets', 'el-icon-bell']
export default {
  components: {
    XdhLayout,
    XdhNavTabs,
    XdhMenuToggle
  },
  data() {
    return {
      tabStore: STORE_NAME,
      menuCollapsed: true,
      northOpt: { height: 'auto' }
    }
  },
  computed: {
    westOpt() {
      return {
        width: this.menuCollapsed ? '64px' : '200px'
      }
    },
    menus() {
      return this.$router.options.routes[1].children.filter((item) => {
        return item.meta && item.meta.menu
      }).map((item, index) => {
        return {
          id: item.path,
          text: item.name,
          icon: iconList[index % iconList.length]
        }
      })
    }
  },
  methods: {
    toggleSidebar() {
      this.menuCollapsed = !this.menuCollapsed
    },
    menuSelectHandle(index, indexPath) {
      console.log(index, indexPath)
    }
  },
  created() {
    // 注册导航tabs store模块
    if (!this.$store.state[STORE_NAME]) {
      this.$store.registerModule(STORE_NAME, createStoreModule())
    }
  },
  mounted() {
  }
}
</script>

